//
//  SRCampingTableViewController.m
//  icamping
//
//  Created by Soraia Ferreira on 20/07/14.
//  Copyright (c) 2014 Soraia Ferreira. All rights reserved.
//

#import "SRCampingTableViewController.h"
#import "SRViewController.h"

#import "SRCampingManagement.h"

NSArray *tableData;
NSArray *tableDataDesc;
NSDictionary *tableDataDictionary;

@implementation SRCampingTableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated{
    
    // Initialize table data
    SRCampingGround *camp1 = [SRCampingGround new];
    camp1.name = @"Parque Campismo 1";
    camp1.description = @"Desc Parque Campismo 1";
    camp1.favourite = YES;
    [camp1 print];
    
    SRCampingGround *camp2 = [SRCampingGround new];
    camp2.name = @"Parque Campismo 2";
    camp2.description = @"Desc Parque Campismo 2";
    camp2.favourite = NO;
    
    SRCampingGround *camp3 = [SRCampingGround new];
    camp3.name = @"Parque Campismo 3";
    camp3.description = @"Desc Parque Campismo 3";
    camp3.favourite = YES;
    
    SRCampingGround *camp4 = [SRCampingGround new];
    camp4.name = @"Parque Campismo 4";
    camp4.description = @"Desc Parque Campismo 4";
    camp4.favourite = NO;
    
    SRCampingGround *camp5 = [SRCampingGround new];
    camp5.name = @"Parque Campismo 5";
    camp5.description = @"Desc Parque Campismo 5";
    camp5.favourite = NO;
    
    SRCampingGround *camp6 = [SRCampingGround new];
    camp6.name = @"Parque Campismo 6";
    camp6.description = @"Desc Parque Campismo 6";
    camp6.favourite = YES;
    
    SRCampingGround *camp7 = [SRCampingGround new];
    camp7.name = @"Parque Campismo 7";
    camp7.description = @"Desc Parque Campismo 7";
    camp7.favourite = NO;
    
    SRCampingGround *camp8 = [SRCampingGround new];
    camp8.name = @"Parque Campismo 8";
    camp8.description = @"Desc Parque Campismo 8";
    camp8.favourite = NO;
    
    SRCampingGround *camp9 = [SRCampingGround new];
    camp9.name = @"Parque Campismo 9";
    camp9.description = @"Desc Parque Campismo 9";
    camp9.favourite = NO;
    
    SRCampingGround *camp10 = [SRCampingGround new];
    camp10.name = @"Parque Campismo 10";
    camp10.description = @"Desc Parque Campismo 10";
    camp10.favourite = YES;
    
    SRCampingGround *camp11 = [SRCampingGround new];
    camp11.name = @"Parque Campismo 11";
    camp11.description = @"Desc Parque Campismo 11";
    camp11.favourite = NO;
    
    SRCampingManagement *cm = [SRCampingManagement new];
    [cm addCampingListObject:camp1];
    [cm addCampingListObject:camp2];
    [cm addCampingListObject:camp3];
    [cm addCampingListObject:camp4];
    [cm addCampingListObject:camp5];
    [cm addCampingListObject:camp6];
    [cm addCampingListObject:camp7];
    [cm addCampingListObject:camp8];
    [cm addCampingListObject:camp9];
    [cm addCampingListObject:camp10];
    [cm addCampingListObject:camp11];
    
    
    tableData = [NSArray arrayWithObjects: camp1.name, camp2.name, camp3.name, camp4.name, camp5.name, camp6.name, camp7.name, camp8.name, camp9.name, camp10.name, camp11.name, nil];
    
    tableDataDesc = [NSArray arrayWithObjects: camp1.description, camp2.description, camp3.description, camp4.description, camp5.description, camp6.description, camp7.description, camp8.description, camp9.description, camp10.description, camp11.description, nil];
    
    //tableDataDictionary = [NSDictionary dictionaryWithObjects:tableDataDesc forKeys:tableData];
    
    
    
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    
    if ([segue.identifier isEqualToString:@"ViewDetails"]) {
        
        SRViewController *details = segue.destinationViewController;
        
        SRCampingGround *campDefault = [[SRCampingGround alloc] init];
        campDefault.name = @"CampSora";
        campDefault.description = @"Aie que descrição tãooo linda :)";
        
        details.campingGround = campDefault;
    }
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
 return [tableData count];
 }







- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *simpleTableIdentifier = @"SimpleTableItem";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }
    
    cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
    [cell.textLabel setHighlightedTextColor:[UIColor blackColor]];
    return cell;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Selected row: %d" , indexPath.row);
    
    static NSString *simpleTableIdentifier = @"SimpleTableItem";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }
    
    cell.textLabel.text = [tableDataDesc objectAtIndex:indexPath.row];
    
    NSString *desc = cell.textLabel.text;
    
    
    
    
    UIAlertView*alert =[[UIAlertView alloc] initWithTitle:@"Descrição: "
                                                  message:desc
                                                 delegate:self
                                        cancelButtonTitle:@"OK"
                                        otherButtonTitles:nil];
    [alert show];
    
    
}


 

/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
 {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */

/*
 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
 {
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 // Delete the row from the data source
 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
 } else if (editingStyle == UITableViewCellEditingStyleInsert) {
 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 }
 }
 */

/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
 {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
 {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
